package com.financing.wap.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;




import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;


/**
 * 客户风险评估
 * @author lisu
 *
 */
public class RiskAssessQuestionUtil {
	static Logger logger = Logger.getLogger(RiskAssessQuestionUtil.class);
	static Map<String,Integer> cacheMap = new HashMap<String,Integer>();
	
	public final static String ELEMENT_TITLE = "title";
	public final static String ELEMENT_CONTENT = "content";
	public final static String ELEMENT_SCORE = "score";
	public final static String ELEMENT_ANSWER = "a";
	public final static String ELEMENT_INDEX = "index";
	public final static String ELEMENT_LIST_INDEX = "index";
	public final static String ELEMENT_ANSWER_LIST = "answerList";
	
	//客户风险题库list
	public static List<Map<Object,Object>> allQuestionsList = new ArrayList<Map<Object,Object>>();
	
	static{
		Logger logger = Logger.getLogger(MessageUtil.class);
		SAXReader  saxReader = new SAXReader();
		try {
			Document document = saxReader.read(RiskAssessQuestionUtil.class.getResourceAsStream("/RiskAssessQuestion.xml"));
			Element rootElement=document.getRootElement();  
			@SuppressWarnings("unchecked")
			List<Element> qaList = rootElement.elements("qa");
			
			for(Element qaElement:qaList){
				Map<Object,Object> qMap = new HashMap<Object,Object>();
				List<Map<Object,Object>> answerList = new ArrayList<Map<Object,Object>>();
				String index = qaElement.elementText(ELEMENT_INDEX);
				String title = qaElement.elementText(ELEMENT_TITLE);
				@SuppressWarnings("unchecked")
				List<Element> aList = qaElement.elements(ELEMENT_ANSWER);
				for(Element aElement:aList){
					Map<Object,Object> answer = new HashMap<Object,Object>();
					String content = aElement.elementTextTrim(ELEMENT_CONTENT);
					String score = aElement.elementTextTrim(ELEMENT_SCORE);
					String list_index = aElement.elementTextTrim(ELEMENT_LIST_INDEX);
					answer.put(ELEMENT_CONTENT, content);
					answer.put(ELEMENT_SCORE, score);
					answer.put(ELEMENT_LIST_INDEX, list_index);
					answerList.add(answer);
				}
				qMap.put(ELEMENT_INDEX, index);
				qMap.put(ELEMENT_TITLE, title);
				qMap.put(ELEMENT_ANSWER_LIST, answerList);
				allQuestionsList.add(qMap);
			}
			
		} catch (DocumentException e) {
			logger.error("Init allQuestionsList error :", e);
			throw new RuntimeException(e);
		}
		
	}
	
}
